import axios from 'axios';
axios.defaults.timeout = 80000;   // 超时时间
//axios.defaults.baseURL = apiURL;  // 默认地址

// const headers = {
//   'Content-Type': 'application/json; charset=' + encodeURIComponent('UTF-8'),
// };

axios.interceptors.request.use(
  config => {
    config.headers['Content-Type'] = config.headers['Content-Type'] || 'application/json;charset=UTF-8';
    const Authorization = localStorage.getItem("Authorization")
    const userStr = localStorage.getItem("user");
    let user = null;
    if (userStr) {
      user = JSON.parse(userStr)

      if (user) {
        config.headers.userId = encodeURIComponent(user.userId);
        config.headers.lmUser = encodeURIComponent(user.userId);
        //包含中文，报string contains non ISO-8859-1 code point
        // config.headers.userName = user.userName;
      }
    }
    config.headers['Authorization'] = Authorization;
    return config;
  },
  error => {
    return Promise.reject(error.response);
  });

// 路由响应拦截
// http response 拦截器
// axios.interceptors.response.use(
//   response => {
//     if (response.data.rtn_code == -9999) {
//       window.location = "/"
//     } else {
//       return response;
//     }

//   },
//   error => {
//     // window.location = "/"
//     return Promise.reject(error.response)
//   });
export default axios
